package org.ipower.examsystem.service.impl;

import java.util.ArrayList;
import java.util.List;
import org.ipower.examsystem.dao.MembershipHardwareDao;
import org.ipower.examsystem.domain.MembershipHardware;
import org.ipower.examsystem.service.MembershipHardwareService;
import org.ipower.platform.domain.Pager;
import org.ipower.platform.domain.QueryCondition;

/**
 * 会员硬件绑定服务实现。
 * @author jeasonyoung
 */
public class MembershipHardwareServiceImpl implements MembershipHardwareService{
    private static final long serialVersionUID = 1L;
    private MembershipHardwareDao dao = null;
    
    @Override
    public void setMembershipHardwareDao(MembershipHardwareDao dao) {
        this.dao = dao;
    }
     
    @Override
    public Pager<MembershipHardware> findAll(String ascProperty, boolean isAsc, int start, int limit, List<QueryCondition> entites) {
        return this.dao.findAll(ascProperty, isAsc, start, limit, entites);
    }
   
   
    @Override
    public void saveOrUpdate(MembershipHardware data) {
        if(data != null && data.getMemberID() != null && !data.getMemberID().isEmpty() && data.getHardware() != null && !data.getHardware().isEmpty()){
            List<QueryCondition> where = new ArrayList<QueryCondition>();
            where.add(new QueryCondition("MemberID", data.getMemberID()));
            where.add(new QueryCondition("Hardware", data.getHardware()));
            if(this.dao.loadAll(where) == null){
                this.dao.save(data);
            }else{
                this.dao.update(data);
            }
        }
    }

    @Override
    public void delete(String memberID, String hardware) {
       if(memberID != null && !memberID.isEmpty() && hardware != null && !hardware.isEmpty()){
            List<QueryCondition> where = new ArrayList<QueryCondition>();
            where.add(new QueryCondition("MemberID", memberID));
            where.add(new QueryCondition("Hardware", hardware));
           this.dao.delete(where);
       }
    }
}